using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/*=====================================================================

  File:      _AlsoBought.ascx.cs for Adventure Works Cycles Storefront Sample
  Summary:   List the most common additional products purchased with the current product
  Date:	     June 16, 2003

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */


namespace Microsoft.Samples.SqlServer 
{

    public partial class AlsoBoughtControl : System.Web.UI.UserControl
    {

        public int ProductID;

//         protected AlsoBoughtControl() {
//             this.Init += new System.EventHandler(Page_Init);
//         }

        //*******************************************************
        //
        // The Page_Load event on this page is used to obtain
        // from a database a collection of other products
        // that customers who purchased a product "also bought".
        //
        //*******************************************************
        private void Page_Load(object sender, System.EventArgs e) {

            // Obtain list of products that people who "also bought" an item have purchased.  Databind to list control
            ShoppingCartDB shoppingCart = new ShoppingCartDB();
			String cartID = shoppingCart.GetShoppingCartId();

			try
			{
				alsoBoughtList.DataSource = shoppingCart.GetProductRecommendationsFromCart(cartID);
				alsoBoughtList.DataBind();
			}
			catch (SqlException err)
			{
				// TODO: Do the "install OLAP" popup if this happens for the first time.
			}

			// Hide the list if no items are in it
            if (alsoBoughtList.Items.Count == 0) {
                alsoBoughtList.Visible = false;
            }
        }

        private void Page_Init(object sender, EventArgs e) {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
        }

		#region Web Form Designer generated code
        ///		Required method for Designer support - do not modify
        ///		the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {

        }
		#endregion
    }
}
